package demo;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 最简单的Servlet
 * @author wupan
 */
public class TestServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
//		res.getWriter().println("My Test Success!");
		
		String dateStr = new Date().toString();
		System.out.println(dateStr);
		request.setAttribute("dd", dateStr);
		
		// 重定向 request.setAttribute() 失效, 前后页面不是一个request
//		res.sendRedirect(req.getContextPath() + "/test.jsp");  
		
		// 请求转发，前后页面共享一个request
		request.getRequestDispatcher("test.jsp").forward(request, response);  
	}

}
